package com.koron.order.linepatrol.uav.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.koron.bean.query.PageQuery;
import com.koron.common.core.util.StringUtils;
import com.koron.order.linedefect.base.bean.po.DefectBean;
import com.koron.order.linedefect.base.bean.query.DefectQuery;
import com.koron.order.linedefect.base.service.DefectService;
import com.koron.order.linepatrol.check.service.LinePatrolCheckSatelliteService;
import com.koron.order.linepatrol.uav.bean.VO.LinePatrolUnv;
import com.koron.order.linepatrol.uav.bean.VO.TypeGroup;
import com.koron.order.linepatrol.uav.bean.dto.LinePatrolUnvDTO;
import com.koron.order.linepatrol.uav.bean.query.LinePatrolUnvQuery;
import com.koron.order.linepatrol.uav.mapper.LineUnvDefectPatrolDetailMapper;
import com.koron.order.linepatrol.uav.service.LineUnvDefectPatrolDetailService;
import com.koron.order.risk.base.service.LineRiskService;
import org.koron.ebs.mybatis.SessionFactory;
import org.koron.ebs.mybatis.TaskAnnotation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
*
*/
@Service
public class LineUnvDefectPatrolDetailServiceImpl implements LineUnvDefectPatrolDetailService {

    @Autowired
    LinePatrolCheckSatelliteService linePatrolCheckSatelliteService;

    @Autowired
    LineRiskService lineRiskService;

    @Autowired
    DefectService defectService;



    @Override
    @TaskAnnotation("BatchInsert")
    public Integer BatchInsert(SessionFactory sessionFactory, List<LinePatrolUnv> list) {
        if (StringUtils.isEmpty(list)) {
            return 0;
        }
        LineUnvDefectPatrolDetailMapper mapper = sessionFactory.getMapper(LineUnvDefectPatrolDetailMapper.class);
        return mapper.BatchInsert(list);
    }

    @Override
    @TaskAnnotation("list")
    public PageInfo<LinePatrolUnv> list(SessionFactory sessionFactory, LinePatrolUnvQuery linePatrolUnvQuery, PageQuery pageQuery) {
        LineUnvDefectPatrolDetailMapper mapper = sessionFactory.getMapper(LineUnvDefectPatrolDetailMapper.class);
        PageHelper.startPage(pageQuery.getPage(),pageQuery.getPageSize(),pageQuery.getOrderBy());
        List<LinePatrolUnv> list = mapper.page(linePatrolUnvQuery, pageQuery);
        return new PageInfo<LinePatrolUnv>(list);
    }

    @Override
    @TaskAnnotation("getById")
    public LinePatrolUnv getById(SessionFactory sessionFactory, String id) {
        LineUnvDefectPatrolDetailMapper mapper = sessionFactory.getMapper(LineUnvDefectPatrolDetailMapper.class);
        LinePatrolUnv linePatrolUnv = mapper.getById(id);
        return linePatrolUnv;
    }
    @Override
    @TaskAnnotation("selectDetailById")
    public LinePatrolUnvDTO selectDetailById(SessionFactory factory, String id) {
        LinePatrolUnv linePatrolUnv= getById(factory, id);
        LinePatrolUnvDTO linePatrolUnvDTO = new LinePatrolUnvDTO();
        linePatrolUnvDTO.setLinePatrolUnv(linePatrolUnv);
        //无人机缺陷巡视业务没有核实工单信息

       //无人机缺陷巡视没有风险上报业务
        DefectQuery defectQuery = new DefectQuery();
        defectQuery.setPatrolId(linePatrolUnv.getId());
        List<DefectBean> defectBeans = defectService.queryList(factory, defectQuery);
        linePatrolUnvDTO.setDefectOrders(defectBeans);
        return linePatrolUnvDTO;
    }

    @Override
    @TaskAnnotation("Insert")
    public Boolean Insert(SessionFactory sessionFactory, LinePatrolUnvQuery linePatrolUnvQuery) {
        LineUnvDefectPatrolDetailMapper mapper = sessionFactory.getMapper(LineUnvDefectPatrolDetailMapper.class);
        return   mapper.Insert(linePatrolUnvQuery) > 0;
    }
    @Override
    @TaskAnnotation("update")
    public Boolean update(SessionFactory sessionFactory, LinePatrolUnv linePatrolUnv) {
        LineUnvDefectPatrolDetailMapper mapper = sessionFactory.getMapper(LineUnvDefectPatrolDetailMapper.class);
        return   mapper.update(linePatrolUnv) > 0;
    }


    @Override
    @TaskAnnotation("getTypeGroup")
    public List<TypeGroup> getTypeGroup(SessionFactory sessionFactory){
        LineUnvDefectPatrolDetailMapper mapper = sessionFactory.getMapper(LineUnvDefectPatrolDetailMapper.class);
        return mapper.getTypeGroup();
    }

}
